<script>
    const data = [
        {
            path: "/home",
            element: 'a',
            meta: {
                title: "首页",
                icon: '1',
            },
        },
        {
            path: "/finance",
            element: 'b',
            children: [
                {
                    path: 'salesStatistics',
                    element: '5',
                    meta: {
                        title: "销售统计",
                        icon: '3',
                    },
                }
            ],
            meta: {
                title: "财务",
                icon: '2',
            },
        },
    ];

    function getItem(label, key, icon, children, type) {
        return {
            key,
            icon,
            children,
            label,
            type,
        };
    }

    //写一个递归函数
    function getTree(data) {
        let tree = [];
        for (let i = 0; i < data.length; i++) {
            let item = data[i];
            let children = item.children;
            if (children && children.length > 0) {
                let childrenTree = getTree(children);
                tree.push(getItem(item.label, item.path, item.icon, childrenTree, item.element));
                continue;
            }
            tree.push(getItem(item.label, item.path, item.icon, null, item.element));
        }
        return tree;
    }
    console.log(getTree(data));
</script>